package com.hula.onion.book.server.spider.platforms.jinxinwang;

import com.alibaba.fastjson.JSONObject;
import com.hula.onion.book.server.common.LoginForm;
import com.hula.onion.book.server.model.AccountInfo;
import com.hula.onion.book.server.utils.MD5Utils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * Description:
 * Create Date:2018/1/17 19:49
 *
 * @author shan
 * @version 1.0
 */
@Component
public class JinXinWangSpiderHelper {

    /**
     * 组装请求参数
     *
     * @param form
     * @return
     */
    public Map<String, Object> installRequestParams(LoginForm form) throws Exception {

        Map<String, Object> map = new HashMap<>(4);

        map.put("account", form.getUserName());
        map.put("pass", MD5Utils.MD5Encode(form.getPassword()));
        map.put("referrer", "http://www.jinxin99.cn/?1");
        map.put("JYMID", "");

        return map;

    }

    /**
     * 解析账户余额
     *
     * @param html
     * @return
     */
    public AccountInfo parseAccountBalance(String html) {

        AccountInfo accountInfo = new AccountInfo();

        html = html.substring(1,html.length()-1);

        html = html.replace("\\","");

        String amount = JSONObject.parseObject(html).getString("totalAmount");
        accountInfo.setAmount(new BigDecimal(amount));

        return accountInfo;
    }


}
